package cn.com.nes.site.controller.crm.opportunity.vo;

import cn.com.nes.site.entity.em.UserTypeEnum;
import cn.com.nes.site.entity.em.crm.opportunity.OpportunityClassificationEnum;
import cn.com.nes.site.entity.vo.PageVO;
import cn.com.nes.site.service.crm.opportunity.bo.QueryOpportunityPageBO;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@ApiModel("商机列表分页 - 入参模型")
@Data
public class QueryOpportunityPageVo extends PageVO {

    @ApiModelProperty(value = "客户UUID", notes = "查询客户所有的商务项目列表")
    private String customerUuid;

    @ApiModelProperty(value = "商务项目UUID")
    private String opportunityUuid;

    @ApiModelProperty("负责人")
    private Long opportunityOwnerId;

    @ApiModelProperty("是否关联客户")
    private Boolean relatedCustomer;

    @ApiModelProperty("项目名称")
    private String opportunityName;

    @ApiModelProperty("项目类型")
    private String opportunityType;

    @ApiModelProperty("联系人电话")
    private String personInChargePhone;

    @ApiModelProperty("客户姓名")
    private String customerName;

    @ApiModelProperty("客户性质")
    private String customerNature;

    @ApiModelProperty("项目阶段，值域对应 param_type=16")
    private String opportunityStage;

    @ApiModelProperty("行政区划代码")
    private String xzqhdm;

    @ApiModelProperty("项目地址")
    private String opportunityAddress;

    @ApiModelProperty("主商机UUID")
    private String mainOpportunityUuid;

    @ApiModelProperty("是否查询关联数据，true-查询已关联数据，false-查询未关联数据")
    private Boolean relatedQuery;

    @ApiModelProperty("商务项目分类")
    private OpportunityClassificationEnum opportunityClassification;

    @ApiModelProperty("商务项目分类列表")
    private List<String> opportunityClassifications;

    public QueryOpportunityPageBO convertToBo() {
        QueryOpportunityPageBO bo = new QueryOpportunityPageBO();
        if (StrUtil.isNotEmpty(opportunityUuid)) {
            bo.setOpportunityUuid(opportunityUuid);
        }
        if (StrUtil.isNotEmpty(customerUuid)) {
            bo.setCustomerUuid(customerUuid);
        }
        if (ObjectUtil.isNotNull(opportunityOwnerId)) {
            bo.setOpportunityOwnerId(opportunityOwnerId);
        }
        if (ObjectUtil.isNotNull(relatedCustomer)) {
            bo.setRelatedCustomer(relatedCustomer);
        }
        if (StrUtil.isNotEmpty(opportunityName)) {
            bo.setOpportunityName(opportunityName);
        }
        if (StrUtil.isNotEmpty(customerName)) {
            bo.setCustomerName(customerName);
        }
        if (StrUtil.isNotEmpty(customerNature)) {
            bo.setCustomerNature(customerNature);
        }
        if (StrUtil.isNotEmpty(opportunityStage)) {
            bo.setOpportunityStage(opportunityStage);
        }
        if (StrUtil.isNotEmpty(xzqhdm)) {
            bo.setAreaCode(xzqhdm);
        }
        if (StrUtil.isNotEmpty(opportunityAddress)) {
            bo.setOpportunityAddress(opportunityAddress);
        }
        if (StrUtil.isNotEmpty(opportunityType)) {
            bo.setOpportunityType(opportunityType);
        }
        bo.setMainOpportunityUuid(mainOpportunityUuid);
        bo.setRelatedQuery(relatedQuery);
        bo.setPersonInChargePhone(personInChargePhone);

        if (CollUtil.isNotEmpty(opportunityClassifications)) {
            if (opportunityClassifications.size() == 1) {
                bo.setOpportunityClassificationEnum(OpportunityClassificationEnum.getEnum(opportunityClassifications.get(0)));
                bo.setOpportunityClassifications(null);
            } else {
                bo.setOpportunityClassificationEnum(OpportunityClassificationEnum.COMMON);
                bo.setOpportunityClassifications(opportunityClassifications);
            }
        }
        if (ObjectUtil.isNotNull(opportunityClassification)) {
            bo.setOpportunityClassificationEnum(opportunityClassification);
        }
        bo.setPageid(this.getPageid());
        bo.setPagesize(this.getPagesize());
        bo.setOperateUserId(this.getOperateUserId());
        bo.setOperateUserCompanyId(this.getOperateUserCompanyId());
        bo.setOperateUserType(UserTypeEnum.getEnum(this.getUserInfo().getUserType()));

        return bo;
    }

}
